import java.io.InputStreamReader;
import java.io.BufferedReader;

public class PoemExcercise {
    
    public static void processPoem(String input,String word) {
        int sign = 0; // 如果为0，则输出逗号，如果为1，输出句号+换行
        int count = 0; //统计word出现次数
        for(int i =0; i<input.length(); i++) {
            System.out.print(input.charAt(i));
            if(input.charAt(i) == word.charAt(0)) {
                count++;
            }
            if(i>0 && i%7==6) {
                if(sign == 0) {
                    System.out.print(",");
                    sign = 1;
                } else {
                    System.out.print(".\n");
                    sign = 0;
                }
            }
        }
        System.out.println(word+"的出现次数为:"+count);

    }

    public static void main(String[] args) throws Exception {
        System.out.println("请输入诗词");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        System.out.println("请输入要统计的字");
        String word = br.readLine();
        processPoem(input,word);
    }
}